package com.cpi.cornpp.creditline.converter;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.apache.commons.collections.CollectionUtils;

import com.cpi.cornpp.creditline.dto.CreditLineDTO;
import com.cpi.cornpp.creditline.view.CreditLineView;

/**
 * Credit Line Converter
 * @author Edgar Joao
 *
 */
public class CreditLineConverter {

	
	/**
	 * Credit Line Converter View to DTO
	 * @param view
	 * @return
	 */
	public CreditLineDTO converterCreditLineViewToDTO(CreditLineView view){
		CreditLineDTO creditLineDTO = null;
		creditLineDTO = new CreditLineDTO();
		creditLineDTO.setCreditLineId(view.getCreditLineId());
		creditLineDTO.setDescription(view.getDescription());
		creditLineDTO.setLimit(view.getLimit());
		creditLineDTO.setOutOfCredit(view.getOutOfCredit());
		creditLineDTO.setTax1(view.getTax1());
		creditLineDTO.setTax2(view.getTax2());
		return creditLineDTO;
	}
	
	
	
	/**
	 * Credit Line Converter DTO to View
	 * @param view
	 * @return
	 */
	public CreditLineView converterCreditLineDtoToView(CreditLineDTO dto){
		CreditLineView creditLineView = null;
		creditLineView = new CreditLineView();
		creditLineView.setCreditLineId(dto.getCreditLineId());
		creditLineView.setDescription(dto.getDescription());
		creditLineView.setLimit(dto.getLimit());
		creditLineView.setOutOfCredit(dto.getOutOfCredit());
		creditLineView.setTax1(dto.getTax1());
		creditLineView.setTax2(dto.getTax2());
		return creditLineView;
	}
	
	
	/**
	 * Credit Line Converter List View to DTO 
	 * @param plantDTOs
	 * @return
	 */
	public List convertViews(List creditLineDTOs){
		List creditLineDtos = null;
		creditLineDtos = new ArrayList(0);
		
		if(!CollectionUtils.isEmpty(creditLineDTOs)){
			Iterator iterator = creditLineDTOs.iterator();
			CreditLineView e = null;
			while(iterator.hasNext()){
				e = (CreditLineView) iterator.next();
				creditLineDtos.add(converterCreditLineViewToDTO(e));
			}			
		}
		return creditLineDtos;
	}
	
	
	/**
	 * Credit Line Converter List DTO to View
	 * @param plantDTOs
	 * @return
	 */
	public List convertDTOs (List creditLineViews){
		List creditLineListViews = null;
		creditLineListViews = new ArrayList(0);
		
		if(!CollectionUtils.isEmpty(creditLineViews)){
			Iterator iterator = creditLineViews.iterator();
			CreditLineDTO e = null;
			while(iterator.hasNext()){
				e = (CreditLineDTO) iterator.next();
				creditLineListViews.add(converterCreditLineDtoToView(e));
			}
		}				
		return creditLineListViews;
	}
	
}
